from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime

class AttendanceBase(BaseModel):
    user_id: int
    clock_in_time: Optional[datetime] = None
    clock_out_time: Optional[datetime] = None
    date: str  # 格式: YYYY-MM-DD
    status: Optional[str] = "正常"

class AttendanceCreate(AttendanceBase):
    pass

class AttendanceUpdate(BaseModel):
    clock_in_time: Optional[datetime] = None
    clock_out_time: Optional[datetime] = None
    status: Optional[str] = None

class AttendanceRecord(AttendanceBase):
    id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True

class AttendanceSummary(BaseModel):
    total_days: int
    on_time_days: int
    late_days: int
    absent_days: int
    department_id: Optional[int] = None

class ClockResponse(BaseModel):
    message: str
    user: str
    action: str
    timestamp: datetime
    status: str